<?php
namespace app\index\controller;

class Job extends BaseHome
{
//    public function index()
//    {
//        $res=db("job")->order("sort asc")->select();
//        $this->assign("res",$res);
//
//        $lbp=db("lb")->where("fid=18")->find();
//        $this->assign("lbp",$lbp);
//
//        $lbm=db("lb")->where("fid=19")->find();
//        $this->assign("lbm",$lbm);
//
//        $lbz=db("lb")->where("fid=20")->find();
//        $this->assign("lbz",$lbz);
//
//        return \view('index');
//    }
    public function index()
    {
        $lbp=db("lb")->where("fid=18")->find();
        $this->assign("lbp",$lbp);
        $lbm=db("lb")->where("fid=19")->find();
        $this->assign("lbm",$lbm);
        $id=\input('id');
        if(empty($id)){
            $re=db("al_type")->order("ty_id asc")->limit(1)->find();
            $id=$re['ty_id'];
        }
        $tui=db("al")->where("status=1 and groom=1")->order('sort asc')->find();
        $this->assign("tui",$tui);

        $res=db("al_type")->order("ty_id asc")->select();
        $this->assign("res",$res);

        $list=db("al")->where("status=1 and groom=1 and fid=$id")->where(['id'=>['neq',$tui['id']]])->order(['sort'=>'asc','id'=>'desc'])->paginate(4);
        $this->assign("list",$list);

        $page=$list->render();
        $this->assign("page",$page);

        $type=db("al_type")->where("ty_id=$id")->find();
        $this->assign("type",$type);



        return \view('index');
    }
    public function detail()
    {
        $lbp=db("lb")->where("fid=18")->find();
        $this->assign("lbp",$lbp);
        $lbm=db("lb")->where("fid=19")->find();
        $this->assign("lbm",$lbm);

        $id=\input('id');
        $re=db("al")->where("id=$id")->find();
        $this->assign("re",$re);

        db("al")->where("id=$id")->setInc("browse",1);

        //上一篇
        $pre=db('al')->where("id<$id and status=1")->order("id desc")->limit("1")->find();
        $this->assign("pre",$pre);

        //下一篇
        $nre=db('al')->where("id>$id and status=1")->order("id asc")->limit("1")->find();
        $this->assign("nre",$nre);

        $res=db("al_type")->order("ty_id asc")->select();
        $this->assign("res",$res);

        return \view('detail');
    }
}